package yf.mall.controller.api.app;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.qiniu.util.Json;
import com.yf.annotation.IgnoreAuth;
import com.yf.response.R;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import yf.mall.entity.AppConfigEntity;
import yf.mall.entity.AppCoursePurchaseEntity;
import yf.mall.service.app.AppConfigService;
import yf.mall.service.app.AppCoursePurchaseService;
import yf.mall.vo.AppConfigVo;
import yf.mall.vo.app.AppAboutUsVo;
import yf.mall.vo.app.common.DataResult;
import yf.mall.vo.app.common.ListQuery;
import yf.mall.vo.app.common.ListResult;
import yf.mall.vo.app.course.AppCoursePurchaseVo;
import yf.mall.vo.app.request.CommonRequest;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;


@RestController
@RequestMapping("/api/app/mini")
public class ApiAppMyController extends ApiAppBaseController {


    @Resource
    private AppConfigService appConfigService;

    @RequestMapping(value = "/my/aboutus",
            method = RequestMethod.POST)
    @IgnoreAuth
    public R aboutUs() {


        List<AppConfigEntity> configList = appConfigService.findConfigByKey(Arrays.asList("complaintMobile", "connectMobile", "copyright", "privacyPolicyUrl", "userAgreementUrl", "workTime","productWarnInfo"));
        if (configList.isEmpty()) {
            return R.error("获取不到app信息，请联系系统管理员");
        }
        Map<String, String> configMap = configList.stream().collect(Collectors.toMap(AppConfigEntity::getKey, AppConfigEntity::getValue));
        AppAboutUsVo appAboutUsVo = new AppAboutUsVo();
        appAboutUsVo.setComplaintMobile(configMap.get("complaintMobile"));
        appAboutUsVo.setConnectMobile(configMap.get("connectMobile"));
        appAboutUsVo.setCopyright(configMap.get("copyright"));
        appAboutUsVo.setPrivacyPolicyUrl(configMap.get("privacyPolicyUrl"));
        appAboutUsVo.setUserAgreementUrl(configMap.get("userAgreementUrl"));
        appAboutUsVo.setWorkTime(configMap.get("workTime"));
        appAboutUsVo.setProductWarnInfo(configMap.get("productWarnInfo"));
        return R.ok(appAboutUsVo);
    }

    @RequestMapping(value = "/check-version",
            method = RequestMethod.POST)
    @IgnoreAuth
    public R checkVersion() {
        List<AppConfigEntity> configList = appConfigService.findConfigByKey(Arrays.asList("appVersionCheck"));
        if (configList.isEmpty()) {
            return R.error("获取不到app信息，请联系系统管理员");
        }
        return jsonDataResult(configList.get(0).getValue());
    }

}
